<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
        v-model="searchContent"
      />
      &nbsp;
      <button @click="searchHandle">Search</button>
    </div>
  </section>
</template>

<script>
//引入axios
import axios from "axios";

// https://api.github.com/search/users?q=xxxxxx
export default {
  name: "Header",
  props: ["getData"],
  data() {
    return {
      searchContent: "",
    };
  },
  methods: {
    async searchHandle() {
      this.getData({ isInit: false, isSearch: true });
      //请求回来的数据
      let re = await axios.get(
        `https://api.github.com/search/users?q=${this.searchContent}`
      );
      console.log(re.data.items);
      //请求成功
      this.getData({ isSearch: false, userList: re.data.items });
      //清空输入框
      this.searchContent = ""
    },
  },
};
</script>

<style>
.red {
  background-color: red;
  height: 100px;
}
</style>